const { dealShopConfig } = require('../biztools/shop');
const { get, post } = require('../common/ajax');
const { SHOP_URL } = require('../constants/url');

/**
 * 获取配置信息
 * @param {Number} latitude 经度
 * @param {Number} longitude 纬度
 */
const getShopSetting = async (latitude, longitude) => {
    const res = await get(SHOP_URL.setting, { latitude, longitude });
    console.log('获取的Shop设置为 => ', res);
    return res;
};

/**
 * 获取装修信息
 * @param {Number} id 自营栏目~0 门店栏目~门店ID
 */
const getShopConfig = async (id = 0) => {
    const res = await get(SHOP_URL.config, { id });
    console.log('Config => 装修信息', res);
    return dealShopConfig(res);
};

/**
 * 获取首页基础信息
 */
const getShopBaseInfo = async () => {};

/**
 * 获取门店货架列表
 * @param {Array} storeList 门店列表
 */
const getShopStoreShelfList = async (storeList) => {
    let result = [];
    // 分门店获取栏目信息
    for (let i = 0; i < storeList.length; i++) {
        const item = storeList[i];
        const param = {
            id: item.id,
            group_id: 0,
            query: '',
            page_no: 1,
            page_size: 3,
        };
        const info = await get(SHOP_URL.shelf, param);
        result.push({
            id: item.id,
            name: item.name,
            list: info.prods,
        });
    }
    return result;
};

/**
 * 匹配仓库信息
 */
const matchLibraryInfo = async () => {};

/**
 * 通过ids获取商品列表数据
 */
const getGoodsListByIds = async () => {};

/**
 * 获取商品详情
 */
const getGoodsDetailInfo = async () => {};

/**
 * 获取微信小程序订阅ID
 */
const getNoticeTamplateId = async () => {
    const res = await get(SHOP_URL.templateId);
    return res.template_ids || [];
};

/**
 * 获取直播中的roomID
 */
const getLiveRoomId = async () => {
    const res = await get(SHOP_URL.roomId);
    return res.room_id || '';
};

module.exports = {
    getShopSetting,
    getShopConfig,
    getShopBaseInfo,
    getShopStoreShelfList,
    matchLibraryInfo,
    getGoodsListByIds,
    getGoodsDetailInfo,
    getNoticeTamplateId,
    getLiveRoomId,
};